from django.db import models
from staff.models import *

class Warehouse(models.Model):
    name = models.CharField(max_length=30, null=False, blank=False)
    def __unicode__(self):
        return self.name
    
class ItemTemplate(models.Model):
    name = models.CharField(max_length=100, null=False, blank=False)
    detail = models.CharField(max_length=100, null=False, blank=False)
    minimum = models.IntegerField(null=False, blank=False)
    def __unicode__(self):
        return "%s" % self.name
    
class Obtainment(models.Model):
    date = models.DateField(null=False, blank=False)
    comment = models.TextField(null=True, blank=True)
    provider = models.ForeignKey(Provider)
    closed = models.BooleanField(null=False, blank=False, default=0)
    def __unicode__(self):
        return self.comment
    
class Currency(models.Model):
    name = models.CharField(max_length=30, null=False, blank=False)
    symbol = models.CharField(max_length=3, null=False, blank=False)
    multiplier = models.FloatField(null=False, blank=False)
    def __unicode__(self):
        return self.symbol

class CurrencyModify(models.Model):
    date = models.DateTimeField(null=False, blank=False)
    previous_multiplier = models.FloatField(null=False, blank=False)
    current_multiplier = models.FloatField(null=False, blank=False)
    currency = models.ForeignKey(Currency)
    def __unicode__(self):
        return "%s" % (self.currency.name)

class Item(models.Model):
    warehouse = models.ForeignKey(Warehouse)
    item_template = models.ForeignKey(ItemTemplate)
    serial = models.CharField(max_length=30, null=False, blank=False)
    location = models.CharField(max_length=15, null=False, blank=False)
    expiration = models.DateField(null=True, blank=True)
    basic_price = models.FloatField(null=False, blank=False)
    sale_price = models.FloatField(null=False, blank=False)
    sold = models.BooleanField(null=False, blank=False, default=0)
    currency = models.ForeignKey(Currency)
    obtainment = models.ForeignKey(Obtainment)
    def __unicode__(self):
        return "%s - Serial #%s" % (self.item_template, self.serial)

class Wheel(models.Model):
    size = models.CharField(max_length=15, null=False, blank=False)
    quantity = models.IntegerField(null=False, blank=False)
    warehouse = models.ForeignKey(Warehouse)

class Vinyl(models.Model):
    code = models.CharField(max_length=20, null=False, blank=False)
    name = models.CharField(max_length=30, null=False, blank=False)
    size = models.FloatField(null=False, blank=False)
    quantity = models.FloatField(null=False, blank=False)
    price = models.FloatField(null=False, blank=False)
    currency = models.ForeignKey(Currency)
    warehouse = models.ForeignKey(Warehouse)

class VinylAdded(models.Model):
    quantity = models.FloatField(null=False, blank=False)
    vinyl = models.ForeignKey(Vinyl) 
    obtainment = models.ForeignKey(Obtainment)
    
class WheelAdded(models.Model):
    quantity = models.IntegerField(null=False, blank=False)
    wheel = models.ForeignKey(Wheel)
    obtainment = models.ForeignKey(Obtainment)
